unit fmxt_PurviewLogsList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, fmSimpleEdit, DB, ActnList, ComCtrls, ToolWin, ExtCtrls,
  StdCtrls, DBCtrls, ADODB, cxControls, cxContainer, cxEdit, cxTextEdit,
  cxMemo, cxRichEdit;

type
  Tfrmxt_PurviewLogsList = class(TForm)
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Splitter1: TSplitter;
    dsMaster: TDataSource;
    Panel2: TPanel;
    DBNavigator1: TDBNavigator;
    edtNew: TRichEdit;
    edtOld: TRichEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure RichVscroll(var Msg: Tmessage); //message WM_VSCROLL;
  public
    { Public declarations }
    sOld:wideString;
    sNew:wideString;
    sOldList:TStringList;
    sNewList:TStringList;
    function ParseNewOld:boolean;

  end;

procedure Inter_ModifyList(dateset:TADODataSet);



implementation

uses uMsgBox;

{$R *.dfm}

procedure Inter_ModifyList(dateset:TADODataSet);
var
  frmxt_PurviewLogsList: Tfrmxt_PurviewLogsList;
begin
  DoBusy(True);
  frmxt_PurviewLogsList:= Tfrmxt_PurviewLogsList.Create(nil);
  try
    frmxt_PurviewLogsList.dsMaster.DataSet:= dateset;
    frmxt_PurviewLogsList.sOld:= frmxt_PurviewLogsList.dsMaster.DataSet.FieldByName('Content').Value;
    frmxt_PurviewLogsList.sNew:= frmxt_PurviewLogsList.dsMaster.DataSet.FieldByName('Matter').Value;
    frmxt_PurviewLogsList.ParseNewOld;
    DoBusy(False);
    frmxt_PurviewLogsList.ShowModal;
  finally
    freeandnil(frmxt_PurviewLogsList);
  end;
end;

{ Tfrmxt_PurviewLogsList }

function Tfrmxt_PurviewLogsList.ParseNewOld: boolean;
var
  FindOldIndex,FindNwIndex:integer;
  i:integer;
  tmp:string;
begin
  sOldList:= TStringList.Create;
  sNewList:= TStringList.Create;

  while sOld<>'' do
  begin
    FindOldIndex:=pos('|',sOld);
    if (FindOldIndex=0) then
    begin
      edtOld.Text := sOld;
      break;
    end else
    begin
      //showmessage(copy(sOld, 1, FindOldIndex));
      sOldList.Add(copy(sOld, 1, FindOldIndex));
      sOld:=copy(sOld,FindOldIndex+1,length(sOld));
    end;
  end;

  while sNew<>'' do
  begin
    FindOldIndex:=pos('|',sNew);
    if (FindOldIndex=0) then
    begin
      edtNew.Text := sNew;
      break;
    end else
    begin
      //showmessage(copy(sOld, 1, FindOldIndex));
      sNewList.Add(copy(sNew, 1, FindOldIndex));
      sNew:=copy(sNew,FindOldIndex+1,length(sNew));
    end;
  end;

  for i:=0 to sOldList.Count-1 do
  begin
    if sNewList.Count-1>=i then
    begin
      if sNewList.Strings[i]<>sOldList.Strings[i] then
      begin
        //edtnew.SelAttributes.Color:=  clRed;
        //edtNew.Lines.Add(sNewList.Strings[i]);
        edtOld.SelAttributes.Color:=  clRed;
        edtOld.Lines.Add(sOldList.Strings[i]);
      end else
      begin
        //edtnew.SelAttributes.Color:=  clWindowText;
        //edtNew.Lines.Add(sNewList.Strings[i]);
        edtOld.SelAttributes.Color:=  clWindowText;
        edtOld.Lines.Add(sOldList.Strings[i]);
      end
    end else
    begin
      edtOld.SelAttributes.Color:=  clWindowText;
      edtOld.Lines.Add(sOldList.Strings[i]);
    end;
  end;

  for i:=0 to sNewList.Count-1 do
  begin
    if sOldList.Count-1>=i then
    begin
      if sNewList.Strings[i]<>sOldList.Strings[i] then
      begin
        edtnew.SelAttributes.Color:=  clRed;
        edtNew.Lines.Add(sNewList.Strings[i]);
        //edtOld.SelAttributes.Color:=  clRed;
        //edtOld.Lines.Add(sOldList.Strings[i]);
      end else
      begin
        edtnew.SelAttributes.Color:=  clWindowText;
        edtNew.Lines.Add(sNewList.Strings[i]);
        //edtOld.SelAttributes.Color:=  clWindowText;
        //edtOld.Lines.Add(sOldList.Strings[i]);
      end
    end else
    begin
      edtnew.SelAttributes.Color:=  clWindowText;
      edtnew.Lines.Add(sNewList.Strings[i]);
    end;
  end;

  freeandnil(sOldList);
  freeandnil(sNewList);
end;

procedure Tfrmxt_PurviewLogsList.Button1Click(Sender: TObject);
begin
  edtNew.SelAttributes.Color:= clBtnFace;
end;

procedure Tfrmxt_PurviewLogsList.RichVscroll(var Msg: Tmessage);
begin
  if Msg.Msg = WM_VSCROLL then
    postMessage(edtOld.Handle, WM_VSCROLL, Msg.WParam, Msg.LParam);
  edtNew.Dispatch(Msg);
end;

procedure Tfrmxt_PurviewLogsList.FormCreate(Sender: TObject);
begin
  edtNew.WindowProc:= RichVscroll;
end;

end.
